﻿@using Matrix.MaKaYunShang.Model.Wechat
@{
    ViewBag.Title = "核销卡劵";
    ViewBag.PathToBtn = "/UserCard/List";
    ViewBag.TextBtn = "核销记录";
    Layout = "~/Views/Shared/_Layout.cshtml";

}
<div class="row" style="">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="dataTable_wrapper">
                    <br />
                    <br />
                    <div style=" text-align: center; margin: 0 auto; width: 60%">
                        <input type="text" class="form-control " name="CardCode" id="CardCode" style="text-align:center;" placeholder="请输入卡劵Code码" />
                    </div>
                    <br />
                    <br />
                    <div style=" text-align: center; margin: 0 auto; width:30%">
                        <a class="btn btn-primary col-lg-10" name="Write_off" id="Write_off">确认核销</a>
                    </div>
                    <br /><br />
                    <div style=" text-align: center; margin: 0 auto; width:30%">
                        @*<a class="btn  col-lg-10" name="get_HYK" id="get_HYK" style=" display:none">扫一扫</a>*@
                    </div>
                    <br />
                    <br />
                </div>
            </div>
        </div>
    </div>
</div>
<script src="~/Content/bootstrap-datetimepicker/jquery/jquery-1.8.3.min.js"></script>
<script src="/Content/alertify-js/js/alertify.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
<script>
    wx.config({
        debug: true,
        appId: '@ViewBag.AppId',
        timestamp: '@ViewBag.timestamp',
        nonceStr: '@ViewBag.nonstr',
        signature: '@JsTicket.getSign(ViewBag.nonstr, ViewBag.jsapi_ticket, ViewBag.timestamp, Request.Url.AbsoluteUri)',
        jsApiList: [
            'checkJsApi',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'onMenuShareQZone',
            'hideMenuItems',
            'showMenuItems',
            'hideAllNonBaseMenuItem',
            'showAllNonBaseMenuItem',
            'translateVoice',
            'startRecord',
            'stopRecord',
            'onVoiceRecordEnd',
            'playVoice',
            'onVoicePlayEnd',
            'pauseVoice',
            'stopVoice',
            'uploadVoice',
            'downloadVoice',
            'chooseImage',
            'previewImage',
            'uploadImage',
            'downloadImage',
            'getNetworkType',
            'openLocation',
            'getLocation',
            'hideOptionMenu',
            'showOptionMenu',
            'closeWindow',
            'scanQRCode',
            'chooseWXPay',
            'openProductSpecificView',
            'addCard',
            'chooseCard',
            'openCard'
        ]
    });
</script>
<script>

    $(function() {
        document.querySelector('#get_HYK').onclick = function() {
            wx.scanQRCode();
            wx.scanQRCode({
                needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
                scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
                success: function(res) {
                    //  alertify.okBtn("确定").cancelBtn("取消").confirm("确认要核销吗", function () {
                    var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
                    $.ajax({
                        type: "POST",
                        url: '/Verify/AjaxVerify',
                        data: { code: result },
                        error: function(request) {
                            alertify.alert("服务器错误!");
                        },
                        success: function(data) {
                            if (data.Status) {
                                alert(data.Message);
                            } else {
                                alertify.alert(data.Message);
                            }
                        }
                    });
                    // });

                }
            });
        };
    });
  
</script>
<script type="text/javascript">
    var ua = window.navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        $("#get_HYK").show();
    }
    //核销卡劵
    $("#Write_off").click(function () {
        var cardCode = $("#CardCode").val();
        if (cardCode == null || cardCode == "") {
           alert("请输入卡券编号");
            return false;
        }
        //alertify.okBtn("确定").cancelBtn("取消").confirm("确认要核销吗", function () {
            $.ajax({
                type: "POST",
                url: '/Verify/AjaxVerify',
                data: { code: cardCode },
                error: function (request) {
                    alertify.alert("服务器错误!");
                },
                success: function (data) {
                    if (data.Status) {
                        //查询卡劵状态
                        //location.href = "/Merchant/CardVerfyResult?code=" + cardCode;
                        alert(data.Message);
                    } else {
                        alert(data.Message);
                    }
                }
           // });
        });
    });
</script>